#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
import requests
from base_spider import BaseSpider

class BestbuySpider(BaseSpider):
  def __init__(self, spider):
    super().__init__(spider)

  def getData(self):
    headers = {
      'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
    }
    req = requests.get(self.url, headers=headers)
    soup = BeautifulSoup(req.text)
    price = soup.find('div', class_='pb-hero-price pb-purchase-price').contents[0].get_text()
    title = soup.find('div', class_="sku-title").contents[0].string
    sku = soup.find(id = 'sku-value').string

    return {
      'price': price,
      'title': title,
      'sku': sku,
    }

  def setToDb(self):
    super().setToDb('bestbuy')


